import {
	$get,
	$post
} from '@/common/request.js'
export default {
	namespaced: true, //开启命名空间后，访问所有属性都需要待模块名
	state() {
		return {
			name: '',
			age: '',
			userInfo:null
		}
	},
	mutations: {
		initName(state, name) {
			state.name = name
		},
		initAge(state, age) {
			state.age = age
		},
		initUserInfo(state,info){
			state.userInfo = info
		},
		clearUserInfo(state){
			state.userInfo = null
		}
	},
	actions: {
		// 异步的
		userLoginAct(context, data) {
			$post('/iaiqsmde9fea569965ed56ab98ea0501752fe631902841e/login',data).then(res => {
				context.commit('initName',res.userName)
				context.commit('initAge',res.age)
				context.commit('initUserInfo',res)
				uni.showToast({
					title: '登录成功',
					icon: 'none'
				})
				uni.setStorage({
					key:'userInfo',
					data:res
				})
				uni.navigateBack({
					delta:1
				})
			});
		}
	}
}
